package com.example.testcomposeproject.pages.copy

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.ioidea.base.PreviewPhoneSize.PreviewPhoneSize
import com.ioidea.base.theme.AppTheme
import com.ioidea.base.widget.LoadingDialog
import com.ioidea.base.widget.Toolbar

/**
 * @author: hemin
 * @date: 2024/6/21
 * @Desc:
 */
@Preview(showBackground = true, device = PreviewPhoneSize)
@Composable
fun PreViewCopyUI(modifier: Modifier = Modifier) {
    AppTheme {
        CopyUI(modifier = modifier, onClickBack = {})

    }
}

/**
 * viewModel 用这个方法
 */
@Composable
fun CopyScreen(modifier: Modifier = Modifier, viewModel: CopyViewModel = hiltViewModel(), onClickBack:()->Unit) {
    val uiState by viewModel.uiState.collectAsStateWithLifecycle()
    CopyUI(modifier,onClickBack)
    LoadingDialog(
        message = uiState.isShowDialog.text,
        showDialog = uiState.isShowDialog.loading
    )
}

/**
 * 真正的UI元素
 */
@Composable
fun CopyUI(modifier: Modifier = Modifier, onClickBack: () -> Unit) {
    Column(modifier = modifier.fillMaxSize()) {
        Toolbar(title = "copy screen", showRightIcon1 = false, onClickBack = onClickBack)
    }
}